package lesson04;



public class Demo_401 {
    public static void main(String[] args) throws InterruptedException {

        test test1=new test();
        test test2=new test();
        Thread thread1 =new Thread(()->{
            for(int i=0;i<5000000;i++)
            test1.func();
        });
        Thread thread2 =new Thread(()->{
            for(int i=0;i<5000000;i++)
            test2.func2();
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(test.count);
    }
}

class  test{
    static int count=0;
    //int count=0;
    static Object o=new Object();
    public  void func(){
        //其他模块放外面，当count++时候加锁
        synchronized (o) {
            count++;
        }
    }
    public  void func2(){
        //其他模块放外面，当count++时候加锁
        synchronized (String.class) {
            count++;
        }
    }

}
